# -*- coding: utf-8 -*-
# @Time    : 2020/5/15 9:57
# @Author  : suhong
# @File    : models.py
# @Software: PyCharm

from tortoise import fields, models
from tortoise.contrib.pydantic import pydantic_model_creator


class CheckDetailNum(models.Model):
    """
    The CheckDetailNum model
    """

    key = fields.CharField(pk=True,max_length=30)
    cid = fields.CharField(max_length=2)
    pagenum = fields.CharField(max_length=10, null=True)
    count = fields.CharField(max_length=10, null=True)
    title = fields.TextField()
    url = fields.CharField(max_length=255, null=True)
    create_time = fields.DatetimeField(auto_now_add=True)
    update_time = fields.DatetimeField(auto_now=True)

    # def full_name(self) -> str:
    #     """
    #     Returns the best name
    #     """
    #     if self.name or self.family_name:
    #         return f"{self.name or ''} {self.family_name or ''}".strip()
    #     return self.username

    # class PydanticMeta:
    #     computed = ["full_name"]
    #     exclude = ["password_hash"]

    class Meta:
        app = "db209"
        table = "check_detail_num"

    class PydanticMeta:
        exclude = ("create_time", "update_time")

class MgIdNum(models.Model):
    id_ = fields.CharField(pk=True,max_length=50)
    stat = fields.IntField(default=0)
    create_time = fields.DatetimeField(auto_now_add=True)
    update_time = fields.DatetimeField(auto_now=True)


    class Meta:
        app = "db209"
        table = "mg_id_num"

    class PydanticMeta:
        exclude = ("create_time", "update_time")

class PageNum(models.Model):
    cid = fields.CharField(max_length=10)
    cid_pagenum = fields.CharField(pk=True,max_length=100)
    stat = fields.IntField(default=0)
    failcount = fields.IntField(default=0)
    createtime = fields.DatetimeField(auto_now_add=True)
    uptime = fields.DatetimeField(auto_now=True)

    class Meta:
        app = "db209"
        table = "pagess"

    class PydanticMeta:
        exclude = ("createtime", "uptime")



CheckDetailNum_Pydantic = pydantic_model_creator(CheckDetailNum, name="CheckDetailNum")
MgIdNum_Pydantic = pydantic_model_creator(MgIdNum, name="MgIdNum")
PageNum_Pydantic = pydantic_model_creator(PageNum, name="PageNum")